package com.google.gwt.sample.dynatablerf.server.business.impl;

import java.util.List;

import com.google.gwt.sample.dynatablerf.server.business.Controlador;
import com.google.gwt.sample.dynatablerf.server.dao.IDAOManager;
import com.google.gwt.sample.dynatablerf.server.domain.AbstractEntity;
import com.google.gwt.sample.dynatablerf.server.domain.EntityQueryParams;

public class ControladorImpl<T extends AbstractEntity, G extends EntityQueryParams>
		implements Controlador<T, G> {

	private IDAOManager<T, G> daoManager;

	@Override
	public T persist(T entity) {
		return daoManager.persist(entity);
	}

	@Override
	public void persist(List<T> list) {
		if (list != null) {
			for (T t : list) {
				daoManager.persist(t);
			}
		}
	}

	public IDAOManager<T, G> getDaoManager() {
		return daoManager;
	}

	public void setDaoManager(IDAOManager<T, G> daoManager) {
		this.daoManager = daoManager;
	}

	@Override
	public T find(G params) {
		return this.daoManager.find(params);
	}

	@Override
	public List<T> findAll(int startIndex, int maxResult) {
		return this.daoManager.findAll(startIndex, maxResult);
	}

	@Override
	public T findById(Long id) {
		return this.daoManager.findById(id);
	}

	@Override
	public Long countAll() {
		return this.daoManager.countAll();
	}

	@Override
	public List<T> findAll(G params, int startIndex, int maxResult) {
		return this.daoManager.findAll(params, startIndex, maxResult);
	}

	@Override
	public Long count(G params) {
		return this.daoManager.count(params);
	}

}